/**
 * Created by dh.huang on 2016/9/1.
 */
/**
 * Created by dh.huang on 2016/8/30.
 */

angular.module('inspinia')
  .controller('treatRecordCtrl', function ($scope,modelList,SweetAlert) {
    $scope.modelList = modelList.modelList;
    $scope.patient =null;
    var patients = modelList.patientForDoctor;
    $scope.records=[];
    var totalAndStatus = {};
    var curentId=-1;

    var findPatient = function(){
      for(var i=0;i<patients.length;i++){
        if(patients[i].id == curentId){
          $scope.patient = patients[i];
          break;
        }
      }
      // window.localStorage.setItem('treatObj',JSON.stringify($scope.patient));
    };

    //图片点击事件，显示列表
    $scope.showTable = function(id){
      curentId = id;
      $scope.records=[];

      // $scope.patient = null;
      // if(!$scope.patient || $scope.patient.id!=id){
        $scope.patient = null;
        findPatient();
      // }
      for(var i=0;i<$scope.patient.payTimes;i++){
        $scope.records.push(totalAndStatus);
      }
      setTimeout(function () {
        $('#mainTable').trigger('footable_redraw');
      }, 100)
    };


    $scope.init = function(){
      $('#search-content').slideToggle(10);
      $('#pm-content').slideToggle(10);
     /* $scope.patient = JSON.parse(localStorage.getItem('treatObj'));
      if ($scope.patient &&　$scope.patient!=undefined && $scope.patient!='') {
        curentId = $scope.patient.id;
        $scope.showTable(curentId);
      }*/
    };

    $scope.init();

    $scope.finish = function(id){
              swal({
          title: "治疗",
          text: "治疗操作是否已完成",
          type: "input",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          closeOnConfirm: true,
          closeOnCancel: true,
          inputPlaceholder:'治疗记录'
        },
        function(inputValue,isConfirm){
          if($scope.patient.treatTimes<$scope.patient.payTimes) {
            $scope.patient.treatTimes += 1;
            $scope.$apply();//解决第一次点击完成按钮时，table没有改变问题
          }
        });
     // window.location.href="#/index/treatment";
    };



  })
